import request from '@/common/vmeitime-http';

/**
 * 创建单聊
 * @param city {String} 城市ID
 * @param to_id {Number} 目标用户ID
 * @param pid {Number} 楼盘ID
 * @param channel_id 非必填 频道ID
 */
export function createPrivateChat(data){
    return request.request({
        isSocket: true,
        url: `/im/mall/channels/one`,
        method: 'post',
        data
    })
}

/**
 * 加入群聊
 * groupId 群聊ID
 */
export function joinGroupChat(groupId){
    return request.request({
        isSocket: true,
        url: `/im/mall/channels/join/${groupId}`,
        method: 'post'
    })
}

/**
 * 获取自己所有聊天频道
 * 
 */
export function getconversations(cityCode){
    return request.request({
        isSocket: true,
        url: `/im/mall/channels/self?city=${cityCode}`
    })
}

/**
 * 加载单聊或群聊频道聊天内容
 * url
 */
export function getChannelContent(url){
    return request.request({
        isSocket: true,
        url
    })
}

/**
 * 搜索所有聊天频道
 * city 城市
 * keyword 关键词
 */
export function searchAllChannel(info){
    return request.request({
        isSocket: true,
        url: `/im/mall/channels?city=${info.cityCode}&keyword=${info.keyword}`
    })
}

/**
 * 设置该频道消息为已读
 */
export function channelMessageAsReadAPI(channelId){
    return request.request({
        isSocket: true,
        url: `/im/mall/channels/read/${channelId}`,
        method: 'post'
    })
}

/**
 * @ desc 请求表情包
 */
export function emojiAPI(url){
    return request.request({
        isSocket: true,
        url: `/im/mall/emoji`
    })
}

/**
 * @ desc 获取当前用户信息
 */
export function getCurrentUserInfo(url){
    return request.request({
        isSocket: true,
        url: `/im/mall/info`
    })
}

/**
 * 退出群聊API
 */
export function quitGroupAPI(channelId){
    return request.request({
        isSocket: true,
        url: `/im/mall/channels/leave/${channelId}`,
        method: 'post',
    })
}

/**
 * 指定用户加入群聊黑名单
 * @param user {Number} 用户id
 * @param channel {String} 频道Id
 * @param black {Boolean} ture/false
 */
export function doBlackList(data){
    return request.request({
        isSocket: true,
        url: `/im/manager/member/black`,
        method: 'post',
        data
    })
}

/**
 * 移出指定用户群聊
 * channel {Number} 频道id
 * user {Number} 用户id
 */
export function shiftOutGroup(data){
    return request.request({
        isSocket: true,
        url: `/im/manager/member/delete`,
        method: 'post',
        data
    })
}

/**
 * 获取群聊内所有成员
 */
export function groupAllUser(url){
    return request.request({
        isSocket: true,
        url
    })
}

/**
 * 获取指定用户是否为黑名单
 * @param userId {Number} 用户id
 */
export function isBlackUser(userId){
    return request.request({
        isSocket: true,
        url: `/im/manager/user/${userId}`
    })
}

/**
 * 获取频道内入驻的所有置业顾问
 * @param channelId {String} required 频道id
 */
export function channelAdvisers(channelId){
    return request.request({
        isSocket: true,
        url: `/im/mall/channels/settle/${channelId}`
    })
}

/**
 * ai聊天问答
 * @param question {string} 问题
*/
export function AIChatAPI(data){
    return request.request({
        url: `/product/mall/ai/question`,
        method: 'post',
        data
    })
}

/**
 * 添加指定销售进入群聊
 * @param {String} uid 用户ID
 * @param {String} channel 频道ID
*/
export function inviteSalesJoinChannel(data){
    return request.request({
        isSocket: true,
        url: `/im/manager/channels/add/user`,
        method: 'post',
        data
    })
}

/**
 * 验证销售是否可以进群
 * @param {String} channel 频道ID
*/
export function checkJoinChannelAuthorize(channel){
    return request.request({
        isSocket: true,
        url: `/im/mall/channels/white/${channel}`
    })
}

/**
 * 猜你喜欢频道内的推送楼盘消息获取
 * @param {String} method post/get
 * @param {Boolean} push 拒收消息true/false
 * 
*/
export function guessChannelMsgs({method='get', push=true }){
    return request.request({
        url: `/product/ads/mall/im/push`,
        method,
        data: {push}
    })
}

/**
 * 猜你喜欢消息推送已读
 * @param {String} method get/post
*/
export function guessMsgHasRead({method='get'}){
    return request.request({
        url: `/product/ads/mall/im/push/read`,
        method
    })
}